const td = require('./TransData.js')
const cfg = require('./config')
running = false
daylyUpdated = false
setInterval(async () => {
    var current = new Date();
    console.log(current.getHours() >= 14)
    console.log(running)

    //if (current.getHours() >= 1 && current.getHours() < 2 && !running) {
    //if (current.getHours() >= 14 && current.getHours() < 20 && !running) {
    if (!running) {
        running = true
        console.log("start trans new")

        try {
            //td.TarnsNew(25)
            await td.TarnsRecentMonth(cfg.updateLastMonths)
        }
        catch (ex) {
            console.log(ex);
        }
        running = false
    }
    if (current.getHours() > cfg.dailyUpdatEndHour) {
        daylyUpdated = false
    }
    if (current.getHours() >= cfg.dailyUpdatStartHour && current.getHours() < cfg.dailyUpdatEndHour
        && !running && daylyUpdated === false) {
        running = true
        console.log("start trans new")

        try {
            //td.TarnsNew(25)
            await td.TarnsRecentMonth(cfg.dailyUpdateLastMonths)
            daylyUpdated = true
        }
        catch (ex) {
            console.log(ex);
        }
        running = false
    }
}, 1000 * cfg.updateInternalTime)